package com.compass.mobile.presenters

import UserInfoManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.models.Appointment
import setUrlCircle

/**
 * Description： 我的预约Presenter
 * Date:2024/5/22 13:48
 */
class AppointmentPresenter : Presenter() {
    private var finalWidth: Int? = null
    fun setFinalWidth(finalWidth: Int?) {
        this.finalWidth = finalWidth
    }

    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view = LayoutInflater.from(viewGroup.context)
            .inflate(R.layout.item_my_appointment, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is Appointment) {
            val vh = viewHolder as ViewHolder
            vh.imgHead.setUrlCircle(item.avatar)
            vh.tvTitle.text=item.shcres
            vh.tvValue.text=item.positionName
            vh.tvDepartments.text=item.nameDept
            vh.tvStatus.text=item.statusName
            vh.tvAppointmentTime.text=item.appointentTime
            vh.tvPatient.text="预约人员：${UserInfoManager.getPatientInfo()?.name}"
            when(item.euStatus){
                "0"->{
                    vh.tvSubmit.text="取消预约"
                } else->{
                    vh.tvSubmit.text="再次预约"
                }
            }


        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {}
    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvTitle: TextView
        var tvValue: TextView
        var tvDepartments: TextView
        var tvAppointmentTime: TextView
        var tvPatient: TextView
        var tvStatus: TextView
        var tvSubmit: TextView
        var imgHead: ImageView

        init {
            tvSubmit = view.findViewById(R.id.tvSubmit)
            tvPatient = view.findViewById(R.id.tvPatient)
            tvStatus = view.findViewById(R.id.tvStatus)
            imgHead = view.findViewById(R.id.imgHead)
            tvTitle = view.findViewById(R.id.tv_title)
            tvValue = view.findViewById(R.id.tvValue)
            tvDepartments = view.findViewById(R.id.tvDepartments)
            tvAppointmentTime = view.findViewById(R.id.tvAppointmentTime)
        }
    }
}
